package com.corpdata.app.customer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.corpdata.app.customer.entity.CustomerTeam;
import com.corpdata.app.customer.service.CustomerInfoService;
import com.corpdata.app.customer.service.CustomerTeamService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.core.base.BaseController;
import com.corpdata.system.log.OptLog;
import com.corpdata.system.log.WebLog;

/**
 * 团队表
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-13 16:46:46
 */
 
@Controller
@RequestMapping("app/customerTeam")
public class CustomerTeamController extends BaseController{

	@Autowired
	private CustomerTeamService customerTeamService;
	
	@Autowired
	private CustomerInfoService customerInfoService;
	
	//新增页面
	@GetMapping("/add/{id}")
	public String add(@PathVariable("id") String id,String cusId,ModelMap map){
		map.put("id", id);
		map.put("cusId", cusId);
		map.put("cusList", customerInfoService.findCustomerAll());
		return "app/customer/team/team_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	@OptLog(info="创建团队",module="团队")
	public Result save(CustomerTeam record,String dicIndustryId,String dicStageId){
		return customerTeamService.insert(record,dicIndustryId,dicStageId);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", customerTeamService.findById(id));
		return "app/customer/team/team_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	@OptLog(info="修改团队",module="团队")
	public Result update(CustomerTeam record){
		return customerTeamService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	@OptLog(info="删除团队",module="团队")
	public Result delete(String id){
		return customerTeamService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return customerTeamService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", customerTeamService.findById(id));
	    return "app/customer/team/team_details";
	}
	
	//详情页面
	@GetMapping("/admission/{id}")
	public String admission(ModelMap map,@PathVariable("id") String id){
		map.put("record", customerTeamService.findById(id));
	    return "app/customer/team/team_admission";
	}
	
	//列表页面
	@GetMapping("/list/{projectId}")
	public String list(ModelMap map,@PathVariable("projectId") String projectId){
		map.put("projectId", projectId);
	    return "app/customer/team/team_list";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return customerTeamService.findByPage(dgRequest);
	}
	
	@ResponseBody
	@RequestMapping("/selectjson/{id}")
	public String getSelectJsonData(@PathVariable("id") String id){
		if(id.equals("all")){
			id = null;
		}
		return customerTeamService.selectAllByCombox(id);
	}
	
	//列表页面
	@GetMapping("/chooseTeam/{projectId}")
	public String chooseTeam(ModelMap map,@PathVariable("projectId") String projectId){
		map.put("projectId", projectId);
		//map.put("list", customerTeamService.selectAllByCombox(projectId));
	    return "app/customer/team/team_choose";
	}
	
	//会议室列表页面
	@GetMapping("/fieldList/{teamId}")
	public String fieldList(ModelMap map,@PathVariable("teamId") String teamId){
		map.put("teamId", teamId);
	    return "app/project/field/field_team_list";
	}
	
	@ResponseBody
	@RequestMapping("/statistics")
	public String statistics(String teamId){
		
		return customerTeamService.statistics(teamId);
	}
	
}
